<#import "../home/masterTemplate.ftl" as layout />
<#include "../macros/utils.ftl" />
<#import "../macros/spring.ftl" as spring />

<#----><#include "/dumps/dump-util.ftl" />

<#assign scriptsObj>
	<#if isMobile()>

	<#else>
		require(["../../js/modules/form", "../../js/profiles/profiles"], function() {
	</#if>
		base.init();
		base.profiles.init();

	<#if !isMobile()>
		});
	</#if>
</#assign>

<#function checkIfPresented topic>
	<#if m_site.m_topicsList??>
		<#assign topicList = m_site.m_topicsList />
		<#list getList(m_site.m_profile.topicsList) as m_topic>
			<#if m_topic.id == topic.id>
				<#return true />
			</#if>
		</#list>
	</#if>
	<#return false />
</#function>

<#macro topicItem topic>
	<div class="row topic">
		<div class="col-md-8">
			<p>${ellipsis(topic.title, 20)}</p>
		</div>
		<div class="col-md-4">
			<div class="btn-group toggle" data-toggle="buttons" data-id="${topic.id}">
				<#assign isPresented = checkIfPresented(topic) />

				<label class="btn btn-primary on <#if isPresented>active</#if> ">
					<input type="radio"  value="1" <#if isPresented>checked</#if> >on
				</label>
				<label class="btn btn-primary off <#if !isPresented>active</#if>">
					<input type="radio" <#if !isPresented>checked</#if> >off
				</label>
	      	</div>
		</div>
	</div>
</#macro>

<@layout.masterTemplate wtSection="" wtSubsection="" title="" bodycss="" wrappercss="bg" section="profiles" subsection="" pagename="" color="" sectionIdx="3">

	<@backHeader "Update" "Profiles" /> 
	<div class="col1-of-2">
		<div class="frm comment-form cf" id="addProfile" data-async="true" data-type="update">
			<div class="btn-group enable-buttons" data-toggle="buttons">
				<label class="btn btn-primary enable">
					<input type="radio"  value="1">enable
				</label>
				<label class="btn btn-primary disable active">
					<input type="radio" checked>disable
				</label>
	      	</div>

			<form action="<@spring.url '/profiles/update_input/' />" method="POST">
			  <input type="hidden" name="id" id="profileId" value="${m_site.m_profile.id}" />
			  <div class="form-group">
			  	<label for="title">title:</label>
			  	<input type="text" class="form-control" id="title" name="title" placeHolder="title" title="title" required="required" data-rules="maxlength:45" value="${m_site.m_profile.title!""}"/>
			  </div>
			  <div class="form-group .wysiwyg">
			  	<label for="description">description:</label>
			  	<textarea class="form-control" id="description" name="description" placeHolder="description" rows="3" title="description" required="required" data-rules="maxlength:255">${m_site.m_profile.description!""}</textarea>
			  </div>
			  <div class="cf confirm"><a class="btn btn-primary submit right" role="button">Save</a></div>
			</form>
		</div>
	</div>
	<div class="col2-of-2">
		<#if m_site.m_topicsList??>

			<div class="topicsWrapper items-wrapper">
				<div class="page-header">
						<h1>Topics <small>Manager</small></h1>
				</div>
				
				<#assign topicList = m_site.m_topicsList />
				<div class="body">
					<input value="<@spring.url '/profiles/manageTopics/' />" type="hidden" id="manageURL"/>
					<#list getList(topicList) as topic>
						<@topicItem topic />
					</#list>
				</div>
			</div>
		</#if>
	</div>
	<#----><@dumper m_site "m_site" false true/>
</@layout.masterTemplate>